home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / SICL / data1.cab / sicl32 / vb / samples / misc / ser_intf.bas < prev    next >
Encoding:
BASIC Source File  |  2001-03-02  |  1.6 KB  |  59 lines

  1.  
  2. '  set_intf.bas
  3. '  This program does the following:
  4. '  1) gets the current configuration of the serial port
  5. '  2) sets it to 9600 baud, no parity, 8 data bits, and
  6. '     1 stop bit
  7. '  3) prints the old configuration
  8. Sub main ()
  9.    Dim intf As Integer
  10.    Dim baudrate As Long
  11.    Dim parity As Long
  12.    Dim databits As Long
  13.    Dim stopbits As Long
  14.    Dim parity_str As String
  15.    Dim msg_str As String
  16.  
  17.    ' open RS-232 interface session
  18.    intf = iopen("COM1")
  19.    Call itimeout(intf, 10000)
  20.  
  21.    ' get baud rate, parity, data bits, and stop bits
  22.    Call iserialstat(intf, I_SERIAL_BAUD, baudrate)
  23.    Call iserialstat(intf, I_SERIAL_PARITY, parity)
  24.    Call iserialstat(intf, I_SERIAL_WIDTH, databits)
  25.    Call iserialstat(intf, I_SERIAL_STOP, stopbits)
  26.  
  27.    ' determine string to display for parity
  28.    Select Case parity
  29.    Case I_SERIAL_PAR_NONE
  30.       parity_str = "NONE"
  31.    Case I_SERIAL_PAR_ODD
  32.       parity_str = "ODD"
  33.    Case I_SERIAL_PAR_EVEN
  34.       parity_str = "EVEN"
  35.    Case I_SERIAL_PAR_MARK
  36.       parity_str = "MARK"
  37.    Case Else
  38.       parity_str = "SPACE"
  39.    End Select
  40.  
  41.    ' set to 9600,NONE,8, 1
  42.    Call iserialctrl(intf, I_SERIAL_BAUD, 9600)
  43.    Call iserialctrl(intf, I_SERIAL_PARITY, I_SERIAL_PAR_NONE)
  44.    Call iserialctrl(intf, I_SERIAL_WIDTH, I_SERIAL_CHAR_8)
  45.    Call iserialctrl(intf, I_SERIAL_STOP, I_SERIAL_STOP_1)
  46.  
  47.    ' display previous settings
  48.    msg_str = "Old settings: " + Str$(baudrate) + "," + parity_str + "," + Str$(databits) + "," + Str$(stopbits)
  49.    MsgBox msg_str, MB_ICON_EXCLAMATION
  50.  
  51.    ' close port
  52.    Call iclose(intf)
  53.  
  54. '  Tell SICL to cleanup for this task
  55.    Call siclcleanup
  56.  
  57. End Sub
  58.  
  59.